class VpnInfo {
    constructor({
                    id = '',
                    tunnelName = '',
                    preShareKey = '',
                    localId = '',
                    parnerId = '',
                    localIp = '',
                    parnerIp = '',
                    ikeMode = '1',
                    isakmpPolicyValue = '',
                    isakmpPolicyValueSet = new Set([]),
                    localSubnet = '',
                    localMask = '',
                    parnerSubnet = '',
                    parnerMask = '',
                    ipsecSASecPolicy = '',
                    ipsecSASecPolicySet = new Set([]),
                    ike_ept_type = '3des',
                    ike_hash_type = 'sha1',
                    ike_dh_type = 'modp768',
                    ike_ept_type1 = '3des',
                    ike_hash_type1 = 'sha1',
                    ike_dh_type1 = 'modp768',
                } = {}) {
        this.id = id;
        this.tunnelName = tunnelName;
        this.preShareKey = preShareKey;
        this.localId = localId;
        this.parnerId = parnerId;
        this.localIp = localIp;
        this.parnerIp = parnerIp;
        this.ikeMode = ikeMode;
        this.isakmpPolicyValue = isakmpPolicyValue;
        this.isakmpPolicyValueSet = isakmpPolicyValueSet;
        this.localSubnet = localSubnet;
        this.localMask = localMask;
        this.parnerSubnet = parnerSubnet;
        this.parnerMask = parnerMask;
        this.ipsecSASecPolicy = ipsecSASecPolicy;
        this.ipsecSASecPolicySet = ipsecSASecPolicySet;
        this.ike_ept_type = ike_ept_type;
        this.ike_hash_type = ike_hash_type;
        this.ike_dh_type = ike_dh_type;
        this.ike_ept_type1 = ike_ept_type1;
        this.ike_hash_type1 = ike_hash_type1;
        this.ike_dh_type1 = ike_dh_type1;
    }
}

const app = new Vue({
    el: '#app',
    data() {
        return {
            formData: new VpnInfo(),
        }
    },
    methods: {
        submitForm() {
            this.$validator.validateAll().then(async (result) => {
                if (result) {
                    //  提交数据
                    var result = await netVpnInfoApi.add(this.formData);
                    if (result.code == 200) {
                        await rxPrompt.msg('新增成功')
                        forward('/network-config/admin_vpn')
                    } else {
                        await rxPrompt.msg(`新增失败,${msg}`)
                        return;
                    }
                } else {
                    rxPrompt.msg('输入存在错误')
                }
            });
        },
        restForm() {
            this.formData = new VpnInfo();
        },
        addType() {
            var setVal = this.formData.ike_ept_type.concat('-', this.formData.ike_hash_type, '-', this.formData.ike_dh_type)
            this.formData.isakmpPolicyValueSet.add(setVal);
            var val = '';
            this.formData.isakmpPolicyValueSet.forEach((obj) => {
                val = val.concat(obj, ',')
            })
            this.formData.isakmpPolicyValue = val;
        },
        addType2() {
            var setVal = this.formData.ike_ept_type1.concat('-', this.formData.ike_hash_type1, '-', this.formData.ike_dh_type1)
            this.formData.ipsecSASecPolicySet.add(setVal);
            var val = '';
            this.formData.ipsecSASecPolicySet.forEach((obj) => {
                val = val.concat(obj, ',')
            })
            this.formData.ipsecSASecPolicy = val;
        },
        cleanType() {
            this.formData.isakmpPolicyValueSet = new Set();
            this.formData.isakmpPolicyValue = '';
        },
        cleanType2() {
            this.formData.ipsecSASecPolicySet = new Set();
            this.formData.ipsecSASecPolicy = '';
        },
    },
})